package com.hjw.httpclient.async;

/**
 * 用来解决 Entity 不能被重复消费的问题
 * 通过堵塞获取 EntityUtils.toString(entity) ，达到重复消费Entity的目的
 * @author hjwStrart
 * @time 2022-11-30 20:36
 * @version: 1.0
 */
public class MyCallBack implements CallBack {

    private boolean competed;
    private String result;

    public String getResult() throws InterruptedException {
        while (!competed) {
            wait(3000);
        }
        return result;
    }

    public void handlerResult(String result) {
        this.competed = true;
        this.result = result;
    }

    @Override
    public void success(String result) {
        handlerResult(result);
    }

    @Override
    public void fail(String result) {
        handlerResult(result);
    }
}
